/*    */ package com.zimbra.cs.service.mail;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.soap.MailConstants;
/*    */ import com.zimbra.common.soap.SoapFaultException;
/*    */ import com.zimbra.cs.mailbox.MailItem.Type;
/*    */ import com.zimbra.cs.mailbox.Mailbox;
/*    */ import com.zimbra.cs.mailbox.Note.Rectangle;
/*    */ import com.zimbra.cs.mailbox.OperationContext;
/*    */ import com.zimbra.cs.service.util.ItemId;
/*    */ import com.zimbra.cs.service.util.ItemIdFormatter;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.Arrays;
/*    */ import java.util.HashSet;
/*    */ import java.util.Map;
/*    */ import java.util.Set;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class NoteAction
/*    */   extends ItemAction
/*    */ {
/*    */   public static final String OP_EDIT = "edit";
/*    */   public static final String OP_REPOSITION = "pos";
/*    */   
/*    */   protected String[] getProxiedIdPath(Element request)
/*    */   {
/* 44 */     String operation = getXPath(request, OPERATION_PATH);
/* 45 */     if ((operation != null) && (NOTE_OPS.contains(operation.toLowerCase())))
/* 46 */       return TARGET_ITEM_PATH;
/* 47 */     return super.getProxiedIdPath(request);
/*    */   }
/*    */   
/*    */ 
/*    */ 
/*    */ 
/* 53 */   private static final Set<String> NOTE_OPS = new HashSet(Arrays.asList(new String[] { "edit", "pos" }));
/*    */   
/*    */ 
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException, SoapFaultException
/*    */   {
/* 59 */     ZimbraSoapContext lc = getZimbraSoapContext(context);
/*    */     
/* 61 */     Element action = request.getElement("action");
/* 62 */     String operation = action.getAttribute("op").toLowerCase();
/*    */     
/* 64 */     if ((operation.endsWith("read")) || (operation.endsWith("spam")))
/* 65 */       throw ServiceException.INVALID_REQUEST("invalid operation on note: " + operation, null);
/*    */     String successes;
/* 67 */     String successes; if (NOTE_OPS.contains(operation)) {
/* 68 */       successes = handleNote(context, request, operation);
/*    */     } else {
/* 70 */       successes = handleCommon(context, request, operation, MailItem.Type.NOTE);
/*    */     }
/* 72 */     Element response = lc.createElement(MailConstants.NOTE_ACTION_RESPONSE);
/* 73 */     Element act = response.addUniqueElement("action");
/* 74 */     act.addAttribute("id", successes);
/* 75 */     act.addAttribute("op", operation);
/* 76 */     return response;
/*    */   }
/*    */   
/*    */   private String handleNote(Map<String, Object> context, Element request, String operation) throws ServiceException {
/* 80 */     Element action = request.getElement("action");
/*    */     
/* 82 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 83 */     Mailbox mbox = getRequestedMailbox(zsc);
/* 84 */     OperationContext octxt = getOperationContext(zsc, context);
/* 85 */     ItemId iid = new ItemId(action.getAttribute("id"), zsc);
/*    */     
/* 87 */     if (operation.equals("edit")) {
/* 88 */       String content = action.getAttribute("content");
/* 89 */       mbox.editNote(octxt, iid.getId(), content);
/* 90 */     } else if (operation.equals("pos")) {
/* 91 */       String strBounds = action.getAttribute("pos", null);
/* 92 */       mbox.repositionNote(octxt, iid.getId(), new Note.Rectangle(strBounds));
/*    */     } else {
/* 94 */       throw ServiceException.INVALID_REQUEST("unknown operation: " + operation, null);
/*    */     }
/* 96 */     return new ItemIdFormatter(zsc).formatItemId(iid);
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/NoteAction.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */